/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import { Visibility } from "./common";

export const protobufPackage = "slash.store";

export interface Collection {
  id: number;
  parentId: number;
  type: string;
  creatorId: number;
  createdTs: number;
  updatedTs: number;
  name: string;
  title: string;
  description: string;
  shortcutIds: number[];
  visibility: Visibility;
}

function createBaseCollection(): Collection {
  return {
    id: 0,
    parentId: 0,
    type: "",
    creatorId: 0,
    createdTs: 0,
    updatedTs: 0,
    name: "",
    title: "",
    description: "",
    shortcutIds: [],
    visibility: 0,
  };
}

export const Collection = {
  encode(message: Collection, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.id !== 0) {
      writer.uint32(8).int32(message.id);
    }
    if (message.parentId !== 0) {
      writer.uint32(16).int32(message.parentId);
    }
    if (message.type !== "") {
      writer.uint32(26).string(message.type);
    }
    if (message.creatorId !== 0) {
      writer.uint32(32).int32(message.creatorId);
    }
    if (message.createdTs !== 0) {
      writer.uint32(40).int64(message.createdTs);
    }
    if (message.updatedTs !== 0) {
      writer.uint32(48).int64(message.updatedTs);
    }
    if (message.name !== "") {
      writer.uint32(58).string(message.name);
    }
    if (message.title !== "") {
      writer.uint32(66).string(message.title);
    }
    if (message.description !== "") {
      writer.uint32(74).string(message.description);
    }
    writer.uint32(82).fork();
    for (const v of message.shortcutIds) {
      writer.int32(v);
    }
    writer.ldelim();
    if (message.visibility !== 0) {
      writer.uint32(88).int32(message.visibility);
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): Collection {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseCollection();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 8) {
            break;
          }

          message.id = reader.int32();
          continue;
        case 2:
          if (tag !== 16) {
            break;
          }

          message.parentId = reader.int32();
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }

          message.type = reader.string();
          continue;
        case 4:
          if (tag !== 32) {
            break;
          }

          message.creatorId = reader.int32();
          continue;
        case 5:
          if (tag !== 40) {
            break;
          }

          message.createdTs = longToNumber(reader.int64() as Long);
          continue;
        case 6:
          if (tag !== 48) {
            break;
          }

          message.updatedTs = longToNumber(reader.int64() as Long);
          continue;
        case 7:
          if (tag !== 58) {
            break;
          }

          message.name = reader.string();
          continue;
        case 8:
          if (tag !== 66) {
            break;
          }

          message.title = reader.string();
          continue;
        case 9:
          if (tag !== 74) {
            break;
          }

          message.description = reader.string();
          continue;
        case 10:
          if (tag === 80) {
            message.shortcutIds.push(reader.int32());

            continue;
          }

          if (tag === 82) {
            const end2 = reader.uint32() + reader.pos;
            while (reader.pos < end2) {
              message.shortcutIds.push(reader.int32());
            }

            continue;
          }

          break;
        case 11:
          if (tag !== 88) {
            break;
          }

          message.visibility = reader.int32() as any;
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<Collection>): Collection {
    return Collection.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<Collection>): Collection {
    const message = createBaseCollection();
    message.id = object.id ?? 0;
    message.parentId = object.parentId ?? 0;
    message.type = object.type ?? "";
    message.creatorId = object.creatorId ?? 0;
    message.createdTs = object.createdTs ?? 0;
    message.updatedTs = object.updatedTs ?? 0;
    message.name = object.name ?? "";
    message.title = object.title ?? "";
    message.description = object.description ?? "";
    message.shortcutIds = object.shortcutIds?.map((e) => e) || [];
    message.visibility = object.visibility ?? 0;
    return message;
  },
};

declare const self: any | undefined;
declare const window: any | undefined;
declare const global: any | undefined;
const tsProtoGlobalThis: any = (() => {
  if (typeof globalThis !== "undefined") {
    return globalThis;
  }
  if (typeof self !== "undefined") {
    return self;
  }
  if (typeof window !== "undefined") {
    return window;
  }
  if (typeof global !== "undefined") {
    return global;
  }
  throw "Unable to locate global object";
})();

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
  : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
  : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
  : Partial<T>;

function longToNumber(long: Long): number {
  if (long.gt(Number.MAX_SAFE_INTEGER)) {
    throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
  }
  return long.toNumber();
}

if (_m0.util.Long !== Long) {
  _m0.util.Long = Long as any;
  _m0.configure();
}
